home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 12.9 KB | 433 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRgnShp.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h"
- #endif
-
- #ifndef FWDFAULT_H
- #include "FWDfault.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWARCSHP_H
- #include "FWArcShp.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- //==============================================================================
- // •• RunTime Info
- //==============================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- //==============================================================================
- // •• class FW_CRegionShape
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape() :
- FW_CShape()
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(XMPShape* xmpShape) :
- FW_CShape()
- {
- SetRep(new FW_CRegionShapeRep(xmpShape));
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(const FW_CRect& rect) :
- FW_CShape()
- {
- SetRep(new FW_CRegionShapeRep(rect));
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(const FW_CRegionShape& other) :
- FW_CShape(other)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(FW_CRegionShapeRep* rep) :
- FW_CShape(rep)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator=
- //------------------------------------------------------------------------------
-
- FW_CRegionShape& FW_CRegionShape::operator=(const FW_CRegionShape& other)
- {
- SetRep(other.GetRep());
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator=
- //------------------------------------------------------------------------------
-
- FW_CRegionShape& FW_CRegionShape::operator=(FW_CRegionShapeRep* other)
- {
- SetRep(other);
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator FW_COvalShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::operator FW_COvalShape() const
- {
- FW_COvalShape ovalShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
- ovalShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return ovalShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator FW_CRoundRectShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::operator FW_CRoundRectShape() const
- {
- FW_CRoundRectShape roundRectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), FW_kZeroPoint);
- roundRectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return roundRectShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator FW_CArcShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::operator FW_CArcShape() const
- {
- FW_CArcShape arcShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), 0, 0);
- arcShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return arcShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator FW_CLineShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::operator FW_CLineShape() const
- {
- FW_CRect rect = ((FW_CShapeRep*)GetRep())->GetShapeBounds();
- FW_CLineShape lineShape(rect[FW_kTopLeft], rect[FW_kBotRight]);
- lineShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return lineShape;
- }
-
- //------------------------------------------------------------------------------
- // FW_CRegionShape::operator FW_CRectShape
- //------------------------------------------------------------------------------
-
- FW_CRegionShape::operator FW_CRectShape() const
- {
- FW_CRectShape rectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
- rectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
- return rectShape;
- }
-
- //==============================================================================
- // •• class FW_CRegionShapeRep
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::FW_CRegionShapeRep
- //------------------------------------------------------------------------------
-
- FW_CRegionShapeRep::FW_CRegionShapeRep() :
- FW_CShapeRep(gGraphicGlobales.gRegion),
- fXMPShape(NULL)
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::FW_CRegionShapeRep
- //------------------------------------------------------------------------------
-
- FW_CRegionShapeRep::FW_CRegionShapeRep(XMPShape* xmpShape) :
- FW_CShapeRep(gGraphicGlobales.gRegion),
- fXMPShape(::NewXMPShape(xmpShape))
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::FW_CRegionShapeRep
- //------------------------------------------------------------------------------
-
- FW_CRegionShapeRep::FW_CRegionShapeRep(const FW_CRect& rect) :
- FW_CShapeRep(gGraphicGlobales.gRegion),
- fXMPShape(::NewXMPShape(rect))
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::~FW_CRegionShapeRep
- //------------------------------------------------------------------------------
-
- FW_CRegionShapeRep::~FW_CRegionShapeRep()
- {
- delete fXMPShape;
- fXMPShape = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::Draw
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::Draw(FW_CGraphicContext* graphicContext)
- {
- FW_ShapeFills shapeFill = GetShapeFill();
-
- if (shapeFill == FW_kNullShape || fXMPShape == NULL)
- return;
-
- FW_PlatformRegion region = graphicContext->AsPlatformRegion(fXMPShape);
-
- #ifdef FW_BUILD_MAC
- graphicContext->SelectInkAndStyle(GetShapeInk(), GetShapeStyle(), FW_kGeometricShape, shapeFill);
-
- if (shapeFill == FW_kFramed)
- ::FrameRgn(region);
- else
- ::PaintRgn(region);
- #endif
- #ifdef FW_BUILD_WIN
- FW_CWinBrush brush(GetShapeInk(), GetShapeStyle());
-
- if (shapeFill == FW_kFramed)
- {
- XMPCoordinate penSize = GetShapeStyle()->GetPenSize();
- FW_SPlatformPoint point = graphicContext->GetPlatformPoint(FW_CPoint(penSize, penSize));
- ::FrameRgn(graphicContext->GetDC(), region, brush->GetGDIObject(), point.x, point.y);
- }
- else
- ::FillRgn(graphicContext->GetDC(), region, brush->GetGDIObject());
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::DrawRegion
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::DrawRegion(FW_CGraphicContext* graphicContext,
- XMPShape* xmpShape)
- {
- if (gGraphicGlobales.gRegion.fFill == FW_kNullShape)
- return;
-
- FW_PlatformRegion region = graphicContext->AsPlatformRegion(xmpShape);
-
- #ifdef FW_BUILD_MAC
- graphicContext->SelectInkAndStyle(gGraphicGlobales.gRegion.fInk, gGraphicGlobales.gRegion.fStyle, FW_kGeometricShape, gGraphicGlobales.gRegion.fFill);
-
- if (gGraphicGlobales.gRegion.fFill == FW_kFramed)
- ::FrameRgn(region);
- else
- ::PaintRgn(region);
- #endif
- #ifdef FW_BUILD_WIN
- FW_CWinBrush brush(defaultRegion->GetShapeInk(), defaultRegion->GetShapeStyle());
-
- if (gGraphicGlobales.gRegion.fFill == FW_kFramed)
- {
- XMPCoordinate penSize = gGraphicGlobales.gRegion.fStyle->GetPenSize();
- FW_SPlatformPoint point = graphicContext->GetPlatformPoint(FW_CPoint(penSize, penSize));
- ::FrameRgn(graphicContext->GetDC(), region, brush->GetGDIObject(), point.x, point.y);
- }
- else
- ::FillRgn(graphicContext->GetDC(), region, brush->GetGDIObject());
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::GetShapeBounds
- //------------------------------------------------------------------------------
-
- FW_CRect FW_CRegionShapeRep::GetShapeBounds() const
- {
- FW_CRect bounds(0, 0, 0, 0);
-
- if (fXMPShape)
- fXMPShape->GetBoundingBox(&bounds);
-
- return bounds;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::Transform
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::Transform(XMPTransform* transform)
- {
- if (fXMPShape)
- fXMPShape->Transform(transform);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::InverseTransform
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::InverseTransform(XMPTransform* transform)
- {
- if (fXMPShape)
- fXMPShape->InverseTransform(transform);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::MoveShape
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY)
- {
- if (fXMPShape)
- {
- XMPTransform *trans = ::NewXMPTransform(FW_CPoint(deltaX, deltaY));
- fXMPShape->Transform(trans);
- delete trans;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::MoveShapeTo
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::MoveShapeTo(XMPCoordinate x, XMPCoordinate y)
- {
- if (fXMPShape)
- {
- FW_CRect bounds;
- fXMPShape->GetBoundingBox(&bounds);
- MoveShape(x - bounds.left, y - bounds.top);
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::SetXMPShape
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::SetXMPShape(XMPShape* xmpShape)
- {
- if (xmpShape)
- fXMPShape->CopyFrom(xmpShape);
- else
- {
- delete fXMPShape;
- fXMPShape = NULL;
- }
- Changed();
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::SetAsDefault
- //------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::SetAsDefault() const
- {
- SetDefaultProperties(gGraphicGlobales.gRegion);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::HitTest
- //------------------------------------------------------------------------------
-
- FW_HitTestPart FW_CRegionShapeRep::HitTest(const FW_CPoint& test) const
- {
- return FW_kOutside;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::Copy
- //------------------------------------------------------------------------------
-
- FW_CRegionShape FW_CRegionShapeRep::Copy() const
- {
- XMPShape *shape;
- if (fXMPShape == NULL)
- shape = ::NewXMPShape();
- else
- shape = ::NewXMPShape(fXMPShape);
-
- FW_CRegionShape region(shape);
- return region;
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::Flatten(FW_CWritableStream& stream)
- {
- FW_UNUSED(stream);
- // NotYetImplemented();
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CRegionShapeRep::Unflatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShapeRep::Unflatten(FW_CReadableStream& stream)
- {
- FW_UNUSED(stream);
- // NotYetImplemented();
- }
-